package test;

import repast.simphony.parameter.Parameters;
import defectsim.Globals;
import defectsim.SimulationEnvironment;
import defectsim.agents.DefectAgent;
import defectsim.agents.DefectFactory;
import defectsim.agents.PointDefect;
import defectsim.agents.DefectFactory.DefectType;

public class PointDefectSourceTester extends DefectAgent{

	private SimulationEnvironment environment = SimulationEnvironment.getInstance();

	private int nPointDefects;
	private double boxLength;
	private int gridSize;

	public PointDefectSourceTester(){
		Parameters p = environment.getParameters();
		this.boxLength = (Double)p.getValue("spacelength");
		this.gridSize = (Integer)p.getValue("gridsize");
		this.nPointDefects = (Integer)p.getValue("nopointdefects");
	}

	@Override
	public void percept() {
		// TODO Auto-generated method stub

	}

	@Override
	public void mentalUpdate() {
		// TODO Auto-generated method stub

	}

	@Override
	public void act() {
		if (environment.getCurrentTick() == 1.0)
			this.createPointDefects(nPointDefects);

	}

	private void createPointDefects(int nPointDefects){
		double gridScale = gridSize / boxLength;

		PointDefect pointDefect = (PointDefect) DefectFactory.createDefect(DefectType.PointDefect);
		double dx = 3.0;
		double dy = 5.0;
		pointDefect.setX(dx);
		pointDefect.setY(dy);
		pointDefect.setLocationGridX((int)(dx * gridScale));
		pointDefect.setLocationGridY((int)(dy * gridScale));
		pointDefect.setPointDefectSize(1000.0 * 0.255 * Globals.NANOMETER_TO_MICROMETER);
		environment.add(pointDefect);
	}

}
